<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta charset="utf-8" />
    <title>后台管理-文章编辑</title>

    <meta name="keywords" content="{$Think.CONFIG.keywords}" />
    <meta name="description" content="{$Think.CONFIG.description}" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
    <script src="__PUBLIC__/hytn/js/jquery.js" type="text/javascript"></script>
    <include file="Public/head" />
</head>

<body class="no-skin">
<include file="Public/header" />
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try{ace.settings.check('main-container' , 'fixed')}catch(e){}
    </script>

    <include file="Public/sidebar" />
    <div class="main-content">
        <div class="main-content-inner">
            <!-- #section:basics/content.breadcrumbs -->
            <include file="Public/breadcrumbs" />

            <!-- /section:basics/content.breadcrumbs -->
            <div class="page-content">
                <include file="Public/set" />

                <!-- /section:settings.box -->
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <div class="form-horizontal">
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="article_parent_id"> 所属分类</label>
                                <div class="col-sm-9">
                                    <input type="text" name='cate_id' id='cate_id' class="col-xs-10 col-sm-5" value="{$cate_name}" readonly>
                                </div>
                            </div>
                            <div class="space-4"></div>

                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="article_cate_name"> 文章标题 <span class="required">*</span> </label>
                                <div class="col-sm-9">
                                    <input type="text" name='title' id='title' class="col-xs-10 col-sm-5" placeholder="文章标题" value="{$info['title']}">
                                </div>
                            </div>

                            <div class="space-4"></div>

                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="order"> 文章简介 <span class="required">*</span> </label>
                                <div class="col-sm-9">
                                    <input type="text" name="content" id="content" placeholder="文章简介" class="col-xs-10 col-sm-5" value="{$info['content']}">
                                </div>
                            </div>

                            <div class="space-4"></div>
                            <form id="form1" enctype="multipart/form-data" action="{:U('LbPicture/upload')}" method="post">
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="up1"> 列表图片 </label>
                                <div class="col-sm-9">
                                    <div class="col-xs-10 col-sm-5"><input type="file" class="txt_file" id="up1" class="up_img" name="img" accept="image/*">
                                        <img name='pic' id='pic' src="{$info['picture']}" style="width:120px;height:80px;padding-top:10px;">
                                    </div>
                                </div>
                            </div>
                            </form>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1"> 文章详情 </label>
                                <div class="col-sm-6">
                                    <script src="__PUBLIC__/ueditor/ueditor.config.js" type="text/javascript"></script>
                                    <script src="__PUBLIC__/ueditor/ueditor.all.js" type="text/javascript"></script>
                                    <textarea name="detail" class="detail" rows="100%" style="width:100%" id="myEditor">{$info['detail']}</textarea>
                                    <script type="text/javascript">
                                        var editor = new UE.ui.Editor();
                                        editor.render("myEditor");
                                    </script>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="col-md-offset-2 col-md-9">
                                <input type="hidden" name="id" id="ids" value="{$info['id']}">
                                <input type="hidden" name="imgurl" id="imgurl" value="{$info['picture']}">
                                <input type="hidden" name="article_cate_id" id="article_cate_id" value="{$info['article_cate_id']}">
                                <button class="btn btn-info" type="button" onclick='save();'>
                                    <i class="icon-ok bigger-110"></i>
                                    提交
                                </button>

                                &nbsp; &nbsp; &nbsp;
                                <button class="btn btn-info" type="button" onclick='fan();'>
                                    <i class="icon-ok bigger-110"></i>
                                    返回
                                </button>
                            </div>
                        </div>
                        <!-- PAGE CONTENT ENDS -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->
    <include file="Public/footer" />

</div><!-- /.main-container -->
<script src="__PUBLIC__/hytn/js/jquery.form.min.js" type="text/javascript"></script>
<include file="Public/footerjs" />
<script type="text/javascript">
    function fan(){
        var article_cate_id = $('#article_cate_id').val();
        var urls = "{:U('SucList/article_list')}?ids="+article_cate_id;
        window.location.href=urls;
    }
    $(document).ready(function(){
        $('#up1').change(function(){
            preSubmit();
        });
    });
    function preSubmit(){
        $("#form1").ajaxSubmit({
            success: function(data) {
                //回调
                if(data != "fail"){
                    $('#imgurl').val(data);
                    data = "__ROOT__"+data;
                    $('#pic').attr('src',data);

                }else{
                    alert('上传失败');
                }
            },
            error:function(data){
                alert('上传失败2，请重新选择图片');
            }
        })
    }
    function save(){
        var ids = $('#ids').val();
        var article_cate_id = $('#article_cate_id').val();
        var title = $('#title').val();
        var content = $('#content').val();
        var picture = $('#imgurl').val();
        var detail = editor.getContent();
        var details = encodeURIComponent(detail);
        var urls = "{:U('SucList/article_list')}?ids="+article_cate_id;
        if(title == ''){
            bootbox.dialog({
                title: '友情提示：',
                message: "文章标题必须填写",
                buttons: {
                    "success" : {
                        "label" : "确定",
                        "className" : "btn-danger"
                    }
                }
            });
            return;
        }
        if(content == ''){
            bootbox.dialog({
                title: '友情提示：',
                message: "文章简介必须填写",
                buttons: {
                    "success" : {
                        "label" : "确定",
                        "className" : "btn-danger"
                    }
                }
            });
            return;
        }

        $.ajax({
            type: "post",
            url: "{:U('SucList/article_edit')}",
            data: "ids="+ids+"&article_cate_id="+article_cate_id+"&title="+title+"&content="+content+"&picture="+picture+"&detail="+details,
            success: function(data){
                if(data == 1){
                    alert('修改成功！');
                    window.location.href=urls;
                }else{
                    alert('修改失败！');
                }
            }
        });
    }
</script>
</body>
</html>
